package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.SchoolDao;
import com.ef.domain.School;
import com.ef.service.SchoolService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class SchoolServiceImpl extends BaseServiceImpl implements SchoolService {

	private SchoolDao schoolDao;

	public void delete(School entity) {
		entity.setStatus(StatusType.INVALID);
		schoolDao.update(entity);

	}

	public PaginationSupport<School> findByExample(
			CustomExample<School> example, int startIndex, int pageSize) {

		return schoolDao.findPageByExample(example, startIndex, pageSize);
	}

	public School findById(Long id) {

		return schoolDao.findById(id);
	}

	public void saveOrUpdate(School entity) {
		schoolDao.saveOrUpdate(entity);
	}

	public List<School> getAllValid() {
		DetachedCriteria criterion = DetachedCriteria.forClass(School.class);
		criterion.add(Restrictions.eq("status", StatusType.VALID));
    	return schoolDao.findAllByCriteria(criterion);
	}
	
	
	public List<School> findAll() {
		DetachedCriteria criteria = DetachedCriteria.forClass(School.class);
		criteria.add(Restrictions.eq("status", StatusType.VALID));
		return schoolDao.findAllByCriteria(criteria);
	}

	public SchoolDao getSchoolDao() {
		return schoolDao;
	}

	public void setSchoolDao(SchoolDao schoolDao) {
		this.schoolDao = schoolDao;
	}

}
